﻿Public Class perTerceiroProposta
    Inherits perAcessoBD

    Public Sub inserirTerceirosProposta(ByVal iCodProposta As Int32,
                                        ByVal iRevProposta As Int32,
                                        ByVal iCodRegiao As Int32,
                                        ByVal sCodProduto As String,
                                        ByVal iCodTerceiros As Int32,
                                        ByVal dQuantidade As Double,
                                        ByVal dCustoUnitario As Decimal,
                                        ByVal dBDI As Double,
                                        ByVal dValorUnitario As Decimal)
        Dim sSql As String

        sSql = "INSERT INTO proposta_terceiros" & Environment.NewLine &
               "           (codProposta" & Environment.NewLine &
               "           ,revProposta" & Environment.NewLine &
               "           ,codRegiao" & Environment.NewLine &
               "           ,codProduto" & Environment.NewLine &
               "           ,quantidade" & Environment.NewLine &
               "           ,custoUnitario" & Environment.NewLine &
               "           ,bdi" & Environment.NewLine &
               "           ,precoUnitario)" & Environment.NewLine &
               "        VALUES" & Environment.NewLine &
               "           (@codProposta" & Environment.NewLine &
               "           ,@revProposta" & Environment.NewLine &
               "           ,@codRegiao" & Environment.NewLine &
               "           ,@codProduto" & Environment.NewLine &
               "           ,@quantidade" & Environment.NewLine &
               "           ,@custoUnitario" & Environment.NewLine &
               "           ,@bdi" & Environment.NewLine &
               "           ,@precoUnitario)"

        With MyBase.SQLCmd.Parameters
            .Clear()
            .AddWithValue("@codProposta", iCodProposta)
            .AddWithValue("@revProposta", iRevProposta)
            .AddWithValue("@codRegiao", iCodRegiao)
            .AddWithValue("@codProduto", IIf(sCodProduto = String.Empty, DBNull.Value, sCodProduto))
            .AddWithValue("@quantidade", dQuantidade)
            .AddWithValue("@custoUnitario", dCustoUnitario)
            .AddWithValue("@bdi", dBDI)
            .AddWithValue("@precoUnitario", dValorUnitario)
        End With

        MyBase.executarAcao(sSql)
    End Sub

    Public Function retornarTerceirosProposta(ByVal iCodProposta As Int32, ByVal iRevProposta As Int32) As DataTable
        Dim sSql As String

        sSql = "SELECT codRegiao" & Environment.NewLine &
               "      ,numItem" & Environment.NewLine &
               "      ,codProduto" & Environment.NewLine &
               "      ,codTerceiros" & Environment.NewLine &
               "      ,quantidade" & Environment.NewLine &
               "      ,custoUnitario" & Environment.NewLine &
               "      ,quantidade * custoUnitario as custoTotal" & Environment.NewLine &
               "      ,bdi" & Environment.NewLine &
               "      ,precoUnitario" & Environment.NewLine &
               "      ,quantidade * precoUnitario as precoTotal" & Environment.NewLine &
               "  FROM proposta_terceiros" & Environment.NewLine &
               " WHERE codProposta = @codProposta " & Environment.NewLine &
               "   AND revProposta = @revProposta"

        With MyBase.SQLCmd.Parameters
            .Clear()
            .AddWithValue("codProposta", iCodProposta)
            .AddWithValue("revProposta", iRevProposta)
        End With

        Return MyBase.executarConsulta(sSql)

    End Function
End Class
